﻿<UserControl x:Class="BizControl.Presentation.ActivityEditModule.Views.MarksConditionsView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
             xmlns:thisConverters="clr-namespace:BizControl.Presentation.ActivityEditModule.Converters"
             xmlns:controls="clr-namespace:BizControl.Presentation.Infrastructure.Controls;assembly=BizControl.Presentation.Infrastructure"
             xmlns:csla="clr-namespace:Csla.Xaml;assembly=Csla.Xaml"
             x:Name="MarksConditionsControl">

    <UserControl.Resources>
        <thisConverters:BoolToTileStateConverter x:Key="BoolToTileStateConverter" />
        <thisConverters:ConditionTypeToPathConverter x:Key="ConditionTypeToPathConverter" />
        <thisConverters:ConditionTypeToNameConverter x:Key="ConditionTypeToNameConverter" />
        <thisConverters:ConditionTypeToStatePathConverter x:Key="ConditionTypeToStatePathConverter" />
        <thisConverters:ConditionTypeToStateStringConverter x:Key="ConditionTypeToStateStringConverter" />
        <thisConverters:ConditionTypeToStringConverter x:Key="ConditionTypeToStringConverter" />

        <thisConverters:ConditionRequiredValueConverter x:Key="ConditionRequiredValueConverter" />
        <thisConverters:ConditionTypeToElementNameConverter x:Key="ConditionTypeToElementNameConverter" />
        <thisConverters:ConditionTypeToElementStatePathConverter x:Key="ConditionTypeToElementStatePathConverter" />
        <thisConverters:ConditionTypeToElementStateStringConverter x:Key="ConditionTypeToElementStateStringConverter" />

        <thisConverters:ConditionTypeToElementsSourceConverter x:Key="ConditionTypeToElementsSourceConverter" />
        
        <thisConverters:MarkStateToPathConverter x:Key="MarkStateToPathConverter" />
        <thisConverters:MarkStateToStringConverter x:Key="MarkStateToStringConverter" />

        <DataTemplate x:Key="MarksCondtionsHeaderTemplate">
            <StackPanel Margin="5" HorizontalAlignment="Left" Height="90">
                <StackPanel Orientation="Horizontal">
                    <TextBlock Text="Работа:" Margin="2" />
                    <TextBlock Text="{Binding Path=Name}" Margin="2"
                               Width="100" TextWrapping="Wrap" FontWeight="Bold" />
                    <ContentControl Width="20" Height="20"
                                    Content="{Binding Path=State, Converter={StaticResource MarkStateToPathConverter}}"
                                    ToolTip="{Binding Path=State, Converter={StaticResource MarkStateToStringConverter}}" />
                </StackPanel>
            </StackPanel>
        </DataTemplate>

        <DataTemplate x:Key="MarksConditionsContentTemplate">
            <telerik:RadFluidContentControl>
                <telerik:RadFluidContentControl.LargeContent>
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="30" />
                            <RowDefinition Height="30" />
                            <RowDefinition />
                        </Grid.RowDefinitions>
                        <TextBlock Text="Зависимости от работ и задач и ограничения по навыкам пользователей" FontWeight="Bold"
                                   VerticalAlignment="Center" HorizontalAlignment="Left" Margin="2" />
                        <Border VerticalAlignment="Bottom" BorderThickness="0,0,0,1" BorderBrush="{StaticResource BorderDarkBrush}" />
                        <StackPanel Grid.Row="1" HorizontalAlignment="Left" VerticalAlignment="Top">
                            <Border BorderThickness="0,0,0,1" BorderBrush="{StaticResource BorderDarkBrush}">
                                <StackPanel Orientation="Horizontal">
                                    <StackPanel Orientation="Horizontal">
                                        <TextBlock HorizontalAlignment="Left" VerticalAlignment="Center" Margin="2">
                                            <Hyperlink Command="{Binding ElementName=MarksConditionsControl, Path=DataContext.AddActivityMarkConditionCommand}"
                                                       CommandParameter="{Binding}">
                                                <TextBlock Text="Добавить работу" />
                                            </Hyperlink>
                                        </TextBlock>
                                        <controls:InfoToolTipControl Margin="5">
                                            <StackPanel Orientation="Horizontal">
                                                <Image Width="25" Height="25" Source="{StaticResource informationImage}" />
                                                <StackPanel Width="300">
                                                    <TextBlock TextWrapping="Wrap">Добавить работу, завершение которой необходимо для выполнения текущей работы. Это означает, что текущую работу можно завершить, только завершив все работы, от которых она зависит.</TextBlock>
                                                </StackPanel>
                                            </StackPanel>
                                        </controls:InfoToolTipControl>
                                        <Border BorderThickness="1" BorderBrush="{StaticResource SolidBorderBrush}" />
                                    </StackPanel>
                                    <StackPanel Orientation="Horizontal">
                                        <TextBlock HorizontalAlignment="Left" VerticalAlignment="Center" Margin="2">
                                            <Hyperlink Command="{Binding ElementName=MarksConditionsControl, Path=DataContext.AddActivityConditionCommand}"
                                                       CommandParameter="{Binding}">
                                                <TextBlock Text="Добавить задачу" />
                                            </Hyperlink>
                                        </TextBlock>
                                        <controls:InfoToolTipControl Margin="5">
                                            <StackPanel Orientation="Horizontal">
                                                <Image Width="25" Height="25" Source="{StaticResource informationImage}" />
                                                <StackPanel Width="300">
                                                    <TextBlock TextWrapping="Wrap">Добавить задачу, завершение которой необходимо для выполнения текущей работы. Это означает, что текущую работу можно завершить, только завершив все задачи, от которых она зависит.</TextBlock>
                                                </StackPanel>
                                            </StackPanel>
                                        </controls:InfoToolTipControl>
                                        <Border BorderThickness="1" BorderBrush="{StaticResource SolidBorderBrush}" />
                                    </StackPanel>
                                    <StackPanel Orientation="Horizontal">
                                        <TextBlock HorizontalAlignment="Left" VerticalAlignment="Center" Margin="2">
                                            <Hyperlink Command="{Binding ElementName=MarksConditionsControl, Path=DataContext.AddSkillConditionCommand}"
                                                       CommandParameter="{Binding}">
                                                <TextBlock Text="Добавить навык" />
                                            </Hyperlink>
                                        </TextBlock>
                                        <controls:InfoToolTipControl Margin="5">
                                            <StackPanel Orientation="Horizontal">
                                                <Image Width="25" Height="25" Source="{StaticResource informationImage}" />
                                                <StackPanel Width="300">
                                                    <TextBlock TextWrapping="Wrap">Добавить навык, которым должен обладать пользователь, выполняющий данную работу. Это означает, что текущую работу можно назначить только пользователю, обладаюшему данным(-и) навыком(-ами).</TextBlock>
                                                </StackPanel>
                                            </StackPanel>
                                        </controls:InfoToolTipControl>
                                    </StackPanel>
                                </StackPanel>
                            </Border>
                        </StackPanel>
                        <Grid Grid.Row="2" Margin="2">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="270" />
                                <ColumnDefinition />
                            </Grid.ColumnDefinitions>
                            <ListBox x:Name="lbConditions" Background="{x:Null}" ItemsSource="{Binding Path=Conditions}"
                                     Style="{StaticResource DefaultListBoxStyle}">
                                <ListBox.ItemTemplate>
                                    <DataTemplate>
                                        <StackPanel Orientation="Horizontal">
                                            <ContentControl Margin="2" Width="15" Height="15" VerticalAlignment="Top"
                                                            Content="{Binding Path=Type, Mode=OneWay, Converter={StaticResource ConditionTypeToPathConverter}}" />
                                            <TextBlock Margin="2" Width="200" TextWrapping="Wrap" FontWeight="Bold">
                                                <TextBlock.Text>
                                                    <MultiBinding Converter="{StaticResource ConditionTypeToNameConverter}">
                                                        <Binding Path="Type" Mode="OneWay" />
                                                        <Binding Path="RequiredMark" Mode="OneWay" />
                                                        <Binding Path="RequiredActivity" Mode="OneWay" />
                                                    </MultiBinding>
                                                </TextBlock.Text>
                                            </TextBlock>
                                            <ContentControl Width="20" Height="20" VerticalAlignment="Top">
                                                <ContentControl.Content>
                                                    <MultiBinding Converter="{StaticResource ConditionTypeToStatePathConverter}">
                                                        <Binding Path="Type" Mode="OneWay" />
                                                        <Binding Path="RequiredMark" Mode="OneWay" />
                                                        <Binding Path="RequiredActivity" Mode="OneWay" />
                                                    </MultiBinding>
                                                </ContentControl.Content>
                                                <ContentControl.ToolTip>
                                                    <MultiBinding Converter="{StaticResource ConditionTypeToStateStringConverter}">
                                                        <Binding Path="Type" Mode="OneWay" />
                                                        <Binding Path="RequiredMark" Mode="OneWay" />
                                                        <Binding Path="RequiredActivity" Mode="OneWay" />
                                                    </MultiBinding>
                                                </ContentControl.ToolTip>
                                            </ContentControl>
                                        </StackPanel>
                                    </DataTemplate>
                                </ListBox.ItemTemplate>
                            </ListBox>
                            <Grid x:Name="gridSelectedCondition" Grid.Column="1" Margin="2" VerticalAlignment="Top" HorizontalAlignment="Left"
                                  Visibility="{Binding ElementName=lbConditions, Path=SelectedValue, Converter={StaticResource NullToVisibilityConverter}}"
                                  DataContext="{Binding ElementName=lbConditions, Path=SelectedValue}">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="100" />
                                    <ColumnDefinition />
                                </Grid.ColumnDefinitions>
                                <Border BorderThickness="1,0,0,0" VerticalAlignment="Stretch" BorderBrush="{StaticResource SolidBorderBrush}" />

                                <TextBlock Margin="5" FontSize="10pt" HorizontalAlignment="Center" VerticalAlignment="Top"
                                           Text="{Binding Path=Type, Converter={StaticResource ConditionTypeToStringConverter}}" />
                                <StackPanel Grid.Column="1" Orientation="Horizontal" HorizontalAlignment="Left" VerticalAlignment="Top">
                                    <ComboBox Width="280" Height="60"
                                              VerticalAlignment="Center" HorizontalAlignment="Left"
                                              ItemsSource="{Binding Converter={StaticResource ConditionTypeToElementsSourceConverter}}">
                                        <ComboBox.SelectedValue>
                                            <MultiBinding Mode="TwoWay" UpdateSourceTrigger="PropertyChanged" Converter="{StaticResource ConditionRequiredValueConverter}">
                                                <Binding Path="RequiredMark" />
                                                <Binding Path="RequiredActivity" />
                                            </MultiBinding>
                                        </ComboBox.SelectedValue>
                                        <ComboBox.ItemTemplate>
                                            <DataTemplate>
                                                <StackPanel Orientation="Horizontal">
                                                    <ContentControl Margin="2" Width="15" Height="15" VerticalAlignment="Top"
                                                                    Content="{Binding ElementName=gridSelectedCondition, Path=DataContext.Type, Converter={StaticResource ConditionTypeToPathConverter}}" />
                                                    <TextBlock Margin="2" Width="200" TextWrapping="Wrap" FontWeight="Bold">
                                                        <TextBlock.Text>
                                                            <MultiBinding Converter="{StaticResource ConditionTypeToElementNameConverter}">
                                                                <Binding ElementName="gridSelectedCondition" Path="DataContext.Type" />
                                                                <Binding />
                                                            </MultiBinding>
                                                        </TextBlock.Text>
                                                    </TextBlock>
                                                    <ContentControl Width="20" Height="20" VerticalAlignment="Top">
                                                        <ContentControl.Content>
                                                            <MultiBinding Converter="{StaticResource ConditionTypeToElementStatePathConverter}">
                                                                <Binding ElementName="gridSelectedCondition" Path="DataContext.Type" />
                                                                <Binding />
                                                            </MultiBinding>
                                                        </ContentControl.Content>
                                                        <ContentControl.ToolTip>
                                                            <MultiBinding Converter="{StaticResource ConditionTypeToElementStateStringConverter}">
                                                                <Binding ElementName="gridSelectedCondition" Path="DataContext.Type" />
                                                                <Binding />
                                                            </MultiBinding>
                                                        </ContentControl.ToolTip>
                                                    </ContentControl>
                                                </StackPanel>
                                            </DataTemplate>
                                        </ComboBox.ItemTemplate>
                                    </ComboBox>
                                    <csla:PropertyStatus Margin="2" Property="{Binding Path=RequiredMark}" />
                                    <csla:PropertyStatus Margin="2" Property="{Binding Path=RequiredActivity}" />
                                </StackPanel>
                            </Grid>
                        </Grid>
                    </Grid>
                </telerik:RadFluidContentControl.LargeContent>
            </telerik:RadFluidContentControl>
        </DataTemplate>

        <!--<Style x:Key="TileViewStyle" TargetType="telerik:RadTileViewItem">
            <Setter Property="TileState">
                <Setter.Value>
                    <MultiBinding Converter="{StaticResource SelectedMarkToTileStateConverter}">
                        <Binding ElementName="MarksConditionsControl" Path="SelectedMark" />
                        <Binding />
                    </MultiBinding>
                </Setter.Value>
            </Setter>
        </Style>-->

    </UserControl.Resources>

    <Grid>
        <telerik:RadTileView x:Name="ConditionsTileView" IsVirtualizing="True"
                             Grid.Row="2" ItemTemplate="{StaticResource MarksCondtionsHeaderTemplate}"
                             MinimizedRowHeight="100" RowHeight="100"
                             MinimizedColumnWidth="250" ColumnWidth="250"
                             MaximizeMode="ZeroOrOne"
                             ItemsSource="{Binding Model}"
                             ContentTemplate="{StaticResource MarksConditionsContentTemplate}" />
        <!--ItemContainerStyle="{StaticResource TileViewStyle}"-->

    </Grid>
</UserControl>
